﻿using FluentNHibernate.Mapping;

namespace NMA.Infrastructure.NHibernate.Mapping
{
    using NMA.Domain.Model;
    using NMA.Infrastructure.NHibernate.DomainObject;

    /// <summary>
    /// http://stackoverflow.com/questions/1345426/fluent-nhibernate-table-per-hierarchy-mapping-problem
    /// http://stochastyk.blogspot.com/2008/05/domain-services-in-domain-driven-design.html
    /// http://nhforge.org/blogs/nhibernate/archive/2008/09/06/a-fluent-interface-to-nhibernate-part-2-value-objects.aspx
    /// </summary>
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Table("[NMA].[dbo].[User]");
            Id(x => x.Id, "ID").GeneratedBy.Guid();
            Map(x => x.UserName, "UserName").Not.Nullable().Length(30);
            Map(x => x.Password, "Password").Not.Nullable().Length(1000);
            Map(x => x.IsAlive, "IsAlive").Not.Nullable();
            Map(x => x.Description, "Description");
            Component<Address>(x => x.Address, m => {
                m.Map(x => x.Street, "Street").Length(30);
                m.Map(x => x.Ward, "Ward").Length(20);
                m.Map(x => x.District, "District").Length(20);
            });
            Map(x => x.BelongToRole, "Role").Not.Nullable();
            Map(x => x.CreatedDate, "CreatedDate").Not.Nullable();
            Map(x => x.UpdatedDate, "UpdatedDate");
        }
    }
}
